package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.commom.ContractStatus;
import com.yanchangapp.model.bean.ContractListBean;
import com.zxl.baselib.util.formatter.BigDecimalUtils;
import com.zxl.baselib.util.time.TimeUtil;
import com.zxl.baselib.util.ui.ResHelper;

import java.util.List;

/**
 * Created by apple on 2019-08-19.
 * description: 合同Adapter
 */
public class ContractListAdapter extends BaseQuickAdapter<ContractListBean, BaseViewHolder> {

    public ContractListAdapter(int layoutResId, @Nullable List<ContractListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ContractListBean item) {
        // 依据标签,设置背景...
        TextView tvTag =  helper.getView(R.id.tvTag);
        tvTag.setText(item.getStatusName());
        if (ContractStatus.HAS_PASS.getStatus().equals(item.getStatus())){
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_pass));
        }else if (ContractStatus.HAS_REJECT.getStatus().equals(item.getStatus())){
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_reject));
        }else if (ContractStatus.WAIT_SUBMIT.getStatus().equals(item.getStatus())){
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_submit));
        }else {
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_default));
        }

        // 设置四行文字...
        helper.setText(R.id.tvDownTime,ResHelper.getString(R.string.contract_down_time,
                TimeUtil.getDayTime(item.getContractTime())));
        helper.setText(R.id.tvContractNo,ResHelper.getString(R.string.contract_contract_no,
                item.getInvoiceNo()));
        helper.setText(R.id.tvSupplierName,ResHelper.getString(R.string.contract_supplier_name,
                item.getSupName()));
        helper.setText(R.id.tvDownSum,ResHelper.getString(R.string.contract_total_money,
                BigDecimalUtils.keep2Decimal(item.getTotalMoney())));

        LinearLayout llBottomSubmit =  helper.getView(R.id.llBottomSubmit);
        TextView tvModify = helper.getView(R.id.tvModify);
        TextView tvSubmit = helper.getView(R.id.tvSubmit);
        if (item.isFlag()){
            llBottomSubmit.setVisibility(View.VISIBLE);
            if (item.getStatus().equals(ContractStatus.WAIT_SUBMIT.getStatus()) ||
            item.getStatus().equals(ContractStatus.HAS_REJECT.getStatus())){
                tvModify.setVisibility(View.VISIBLE);
            }else {
                tvModify.setVisibility(View.GONE);
            }

            if (item.getStatus().equals(ContractStatus.WAIT_SUBMIT.getStatus())){
                tvSubmit.setVisibility(View.VISIBLE);
            }else {
                tvSubmit.setVisibility(View.GONE);
            }
        }else {
            llBottomSubmit.setVisibility(View.GONE);
        }
        // 添加点击事件...
        helper.addOnClickListener(R.id.tvModify).addOnClickListener(R.id.tvSubmit);

    }
}
